//
//  TabsViewController.m
//  IceBreaker
//
//  Created by Chiao Wolfire on 12-10-6.
//  Copyright (c) 2012年 NDS. All rights reserved.
//

#import "TabsViewController.h"
#import "IceAppDelegate.h"
#import "HomeTabViewController.h"
#import "MessageTabViewController.h"
#import "FriendTabViewController.h"
#import "MineTabViewController.h"
#import "SettingTabViewController.h"
#import "PublicUtils.h"

static IceAppDelegate *appDelegate;

@implementation TabsViewController

@synthesize rootTabs;

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title = @"Tabs";        
        appDelegate = (IceAppDelegate *)[[UIApplication sharedApplication] delegate];
    }
    return self;
}

-(void)viewDidLoad {
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    // Create the hoem tab
    HomeTabViewController *homeTab = [[HomeTabViewController alloc] init];
    UINavigationController *homeNav = [[UINavigationController alloc] initWithRootViewController: homeTab];
    [homeNav.navigationBar setBackgroundImage: [UIImage imageNamed: @"banner.png"]
                                forBarMetrics: UIBarMetricsDefault];
    [homeTab release];
    // Create the message tab
    MessageTabViewController *msgTab = [[MessageTabViewController alloc] init];
    UINavigationController *msgNav = [[UINavigationController alloc] initWithRootViewController: msgTab];
    [msgNav.navigationBar setBackgroundImage: [UIImage imageNamed: @"banner.png"]
                               forBarMetrics: UIBarMetricsDefault];
    [msgTab release];
    // Create the friend tab
    FriendTabViewController *friendTab = [[FriendTabViewController alloc] init];
    UINavigationController *friendNav = [[UINavigationController alloc] initWithRootViewController: friendTab];
    [friendNav.navigationBar setTintColor: [PublicUtils getColor: @"2c3239"]];
    [friendTab release];
    // Create the my activities tab
    MineTabViewController *mineTab = [[MineTabViewController alloc] init];
    UINavigationController *mineNav = [[UINavigationController alloc] initWithRootViewController: mineTab];
    [mineNav.navigationBar setTintColor: [PublicUtils getColor: @"2c3239"]];
    [mineTab release];
    // Create the settings tab
    SettingTabViewController *settingTab = [[SettingTabViewController alloc] init];
    UINavigationController *settingNav = [[UINavigationController alloc] initWithRootViewController: settingTab];
    [settingNav.navigationBar setTintColor: [PublicUtils getColor: @"2c3239"]];
    [settingTab release];
    // init the navigations as an array
    NSArray *controllerArray = [[NSArray alloc] initWithObjects: homeNav, msgNav, friendNav, mineNav, settingNav, nil];
    [homeNav release];
    [msgNav release];
    [friendNav release];
    [mineNav release];
    [settingNav release];
    // init the tabs
    rootTabs = [[UITabBarController alloc] init];
    // rootTabs.view.frame = CGRectMake(0, self.view.frame.size.height - 20, 320, 40);
    rootTabs.delegate = appDelegate;
    rootTabs.viewControllers = controllerArray;
    rootTabs.selectedIndex = 0;
    [controllerArray release];
    
    [appDelegate.window addSubview: rootTabs.view];
}

-(void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
